#include <iostream>
#include <sstream>
#include <string>

namespace std {
    bool isPrime(int num) {
        if (num < 2) {
            return false;
        }
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    int findClosestPrime(int num) {
        int lowerNum = num - 1;
        int upperNum = num + 1;
        while (!isPrime(lowerNum) && !isPrime(upperNum)) {
            lowerNum--;
            upperNum++;
        }
        if (isPrime(lowerNum)) {
            return lowerNum;
        } else {
            return upperNum;
        }
    }
}

using namespace std;

int main() {
    string input;
    cout << "Enter three words in English: ";
    getline(cin, input);
    
    stringstream ss(input);
    string word;
    string numStr = "";
    string numMap[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    
    while (ss >> word) {
        for (int i = 0; i < 10; i++) {
            if (word == numMap[i]) {
                numStr += to_string(i);
                break;
            }
        }
    }
    
    if (numStr.length() == 3) {
        int num = stoi(numStr);
        int result = findClosestPrime(num);
        cout << result << endl;
    } else {
        cout << "Wrong input" << endl;
    }

    return 0;
}
